package rtda.stack;

public class Stack<E> extends java.util.Stack<E> {
    public final int maxSize;

    public Stack(int maxSize) {
        this.maxSize = maxSize;
    }

    @Override
    public E push(E item) {
        // TODO: 为什么是IllegalStateException
        if (this.size() >= maxSize)
            throw new IllegalStateException("StackOverFlow");
        return super.push(item);
    }

    @Override
    public synchronized E pop() {
        E pop = super.pop();
        if (pop == null) {
            throw new IllegalStateException();
        }
        return super.pop();
    }
}
